<!-- 隐患整改 -->
<template>
	<view class="all-shoot-container">
		<view class="top-content">
			<view>
				<uni-data-checkbox mode="tag" v-model="pageStatus" @change="pageChange"
					:localdata="tabs"></uni-data-checkbox>
			</view>
			<uni-nav-bar>
				<block slot="left" style="width: 0;">
				</block>
				<view class="input-view">
					<uni-icons class="input-uni-icon" type="search" size="18" color="#999" />
					<input confirm-type="search" v-model="queryParams.hiddenDangerName" class="nav-bar-input"
						type="text" placeholder="输入搜索关键词" @confirm="confirm" />
				</view>
				<block slot="right">
					<view class="city" @click="searchBtn">
						搜索
					</view>
				</block>
			</uni-nav-bar>

			<view class="add-btn" v-if="pageStatus == 2">
				<view class="middle-font">
					<uni-icons type="plusempty" size="25"></uni-icons>
					<text class="label">新增</text>
				</view>
			</view>
		</view>


		<!-- 审查项 -->
		<view class="check">
			<!-- <uni-card title="" extra="" v-for="(item) in checkList" :key="item.id"> -->
			<z-paging ref="paging" v-model="checkList" @query="queryList">
				<uni-card title="" extra="" v-for="(item, index) in checkList" :key="item.id">
					<uni-list  class="custom-list-item">
						<uni-list-item title="隐患名称" :rightText="item.hiddenDangerName" />
						<uni-list-item title="整改级别">
							<template v-slot:footer>
								<text class="custom-font">{{formatHiddenDangerType(item.hiddenDangerType)}}</text>
							</template>
						</uni-list-item>
						<uni-list-item title="签收时间" :rightText="item.signingTime" />
						<uni-list-item title="整改直接负责人" :rightText="item.personDirectlyResponsibleName" />
						<uni-list-item title="代办人" :rightText="item.personDoneName" />
						<uni-list-item title="状态">
							<template v-slot:footer>
								<text
									class="custom-font">{{formatTaskStatus(item.hiddenDangerStatus)}}</text>
							</template>
						</uni-list-item>
						<uni-list-item title="" v-if="item.button == 1">
							<template v-slot:footer>
								<button type="primary" size="mini"
									@click="handleSubmit(item)">{{ statusButton(item.hiddenDangerStatus) }}</button>
							</template>
						</uni-list-item>
					</uni-list>
				</uni-card>
				
			</z-paging>
			<!-- </uni-card> -->
		</view>
	</view>
</template>

<script>
	import {
		listAllShoot,
		addAllShoot,
		editAllShoot,
		searchHidden,
		deleteAllShoot,
		detailAllShoot,
		submitAllShoot
	} from "@/api/hiddenTrouble/allShoot.js";
	import {
		mapGetters
	} from "vuex"
	import {
		summaryRectList,
		listRect,
	} from "@/api/hiddenTrouble/rectification.js";

	export default {
		props: {
			commpanyaccount: {
				type: String
			}
		},
		data() {
			return {
				pageStatus: 3,
				queryForm: {},
				queryParams: {
					pageNum: 1,
					pageSize: 10
				},
				userInfo: {}, //用户信息
				tabs: [{
						text: '隐患下发',
						value: 3
					},
					{
						text: '计划反馈',
						value: 4
					},
					{
						text: '整改反馈',
						value: 1
					},
					// {
					// 	text: '隐患上报',
					// 	value: 2
					// },
				],
				checkList: []
			}
		},
		methods: {
			/** 根据状态去改变 */
			handleSubmit(row) {
				if (row.hiddenDangerStatus == 1) { //下发
					uni.navigateTo({
						url: `/pages/trouble/managePage/distribute`,
						success: (res) => {
							res.eventChannel.emit('acceptDataFromOpenedPage', {
								operateStatus: 1,
								checkId: row.id,
							})
						}
					})
				} else if (row.hiddenDangerStatus == 2) { //下发
					uni.navigateTo({
						url: `/pages/trouble/managePage/processDistribute`,
						success: (res) => {
							res.eventChannel.emit('acceptDataFromOpenedPage', {
								operateStatus: 1,
								checkId: row.id,
								rowData: row
							})
						}
					})
				} else if (row.hiddenDangerStatus == 3) {
					uni.navigateTo({
						url: `/pages/trouble/managePage/examine`,
						success: (res) => {
							res.eventChannel.emit('acceptDataFromOpenedPage', {
								operateStatus: 1,
								checkId: row.id,
								rowData: row
							})
						}
					})
				}else if (row.hiddenDangerStatus == 4) {//反馈
					uni.navigateTo({
						url: `/pages/trouble/managePage/rectBackExamine`,
						success: (res) => {
							res.eventChannel.emit('acceptDataFromOpenedPage', {
								operateStatus: 1,
								checkId: row.id,
								rowData: row
							})
						}
					})
				}else if (row.hiddenDangerStatus == 5) {//反馈审批
					uni.navigateTo({
						url: `/pages/trouble/managePage/rectBackExamine`,
						success: (res) => {
							res.eventChannel.emit('acceptDataFromOpenedPage', {
								operateStatus: 1,
								checkId: row.id,
								rowData: row
							})
						}
					})
				}
			},
			confirm() {
				uni.showToast({
					title: '搜索'
				})
			},
			//整改级别
			formatHiddenDangerType(val) {
				if (val == 1) {
					return "一般隐患"
				} else if (val == 2) {
					return "重大隐患"
				}
			},
			/** 格式化按钮状态 */
			statusButton(val) {
				if (val == 1 || val == 2) {
					return "下发";
				} else if (val == 3) {
					return "审批";
				} else if (val == 4) {
					return "反馈";
				} else if (val == 5) {
					return "反馈审批";
				} else {
					return "";
				}
			},
			//格式化状态
			formatTaskStatus(val) {
				if (val == 1) {
					return "计划未发中";
				} else if (val == 2) {
					return "计划下发中";
				} else if (val == 3) {
					return "计划审批中";
				} else if (val == 4) {
					return "反馈中";
				} else if (val == 5) {
					return "反馈审批中";
				} else if (val == 1001) {
					return "完成";
				}
			},
			async pageChange(e) {
				let pageStatus = e.detail.value
			},

			//获取当前用户数据
			//根据状态调用不同接口、
			async statusApi(pageStatus) {
				this.$refs.paging.reload()
				if (pageStatus == 1) { //整改反馈
					uni.showLoading({
						title: "加载中"
					})
					this.queryParams.pageStatus = 2;
					let res = await listRect(this.queryParams)
					this.checkList = res.rows
					uni.hideLoading()
					return
				} else if (pageStatus == 2) { //隐患上报
					uni.showLoading({
						title: "加载中"
					})
					let res = await searchHidden()
					this.checkList = res.rows
					uni.hideLoading()
					return
				} else if (pageStatus == 3) { //隐患下发
					uni.showLoading({
						title: "加载中"
					})
					this.userInfo = uni.getStorageSync("userInfo");
					let params = {
						deptId: this.userInfo.companyAccount,
						pageNum: this.queryParams.pageNum,
						pageSize: this.queryParams.pageSize
					}
					let res = await summaryRectList(params)
					this.checkList = res.rows
					uni.hideLoading()
					return
				} else if (pageStatus == 4) { // 计划反馈
					uni.showLoading({
						title: "加载中"
					})
					this.queryParams.pageStatus = 1;
					let res = await listRect(this.queryParams);
					this.checkList = res.rows
					uni.hideLoading()
					return

				}

			},
			//分页方法
			async queryList(pageNum, pageSize) {
				console.log("分页de==", this.pageStatus)
				this.queryParams.pageNum = pageNum
				this.queryParams.pageSize = pageSize
				
				switch (this.pageStatus) {
					case 1:
						let res = await listRect(this.queryParams)
						this.$refs.paging.complete(res.rows);
						return;

					case 2:
						let res2 = await searchHidden(this.queryParams)
						this.$refs.paging.complete(res2.rows);
						return;

					case 3:
						this.userInfo = uni.getStorageSync("userInfo");
						let params = {
							deptId: this.userInfo.companyAccount,
							pageNum: this.queryParams.pageNum,
							pageSize: this.queryParams.pageSize
						}
						let res3 = await summaryRectList(params)
						this.$refs.paging.complete(res3.rows);
						return;
					case 4:
						let res4 = await listRect(this.queryParams)
						this.$refs.paging.complete(res4.rows);
						return;
					default:
						break;
				}
				// const res = await summaryRectList(this.queryParams);
				// // 将请求结果通过complete传给z-paging处理，同时也代表请求结束，这一行必须调用
				// this.$refs.paging.complete(res.rows);
			},
			async searchBtn(val) {
				console.log("查询参数", this.queryParams)
				uni.showLoading({
					title: "加载中"
				})
				let res = await summaryRectList(this.queryParams)
				this.checkList = res.rows
				uni.hideLoading()
			}
		},
		computed: {
			...mapGetters(['deptId', ])
		},
		mounted() {

		},
		watch: {

			pageStatus: {
				handler(val) {
				
					this.statusApi(val)

				},
				immediate: true
			}
		}
	}
</script>

<style lang="scss" scoped>
	.all-shoot-container {
		$nav-height: 30px;
		padding: 24rpx;
		padding-top: 240rpx;

		.top-content {
			position: relative;
			z-index: 11;
		}

		.check {
			.custom-list-item {
				background: #ffffff;
				margin: 16rpx 0;
			}

			.custom-font {
				color: #999;
				font-size: 22rpx;
			}

			.z-paging-content-fixed {
				top: 400rpx;
			}
		}

		::v-deep {
			.uni-navbar {
				.uni-navbar--border {
					background-color: transparent !important;
					border-bottom: none !important;

					.uni-navbar__header {
						background-color: transparent !important;

						.uni-navbar__header-btns-left {
							width: 0 !important;
						}

						.uni-navbar__header-btns-right {
							.city {
								color: #137EE9;
								font-size: 18px;
								font-weight: 400;
							}
						}
					}
				}
			}

			.add-btn {
				width: 100%;
				height: 175rpx;
				border: 2rpx dashed #C5C8CE;

				.middle-font {
					display: flex;
					justify-content: center;
					align-items: center;
					height: 100%;

					.label {
						color: #808695;
					}
				}
			}

			.uni-card {
				.uni-card__header {
					border: none;
				}

				.uni-card__content {
					.uni-group__content {
						padding: 0;
					}

				}
			}
		}

		.input-view {
			/* #ifndef APP-PLUS-NVUE */
			display: flex;
			/* #endif */
			flex-direction: row;
			// width: 500rpx;
			flex: 1;
			background-color: #f8f8f8;
			height: $nav-height;
			border-radius: 15px;
			padding: 0 15px;
			flex-wrap: nowrap;
			margin: 7px 0;
			line-height: $nav-height;
		}

		.input-uni-icon {
			line-height: $nav-height;
		}

		.nav-bar-input {
			height: $nav-height;
			line-height: $nav-height;
			/* #ifdef APP-PLUS-NVUE */
			width: 370rpx;
			/* #endif */
			padding: 0 5px;
			font-size: 12px;
			background-color: #f8f8f8;
		}
	}
</style>